<?php
namespace Kuoqi\Worker;
/**
 * 这个是应用数据应该继承的类
 * Class Event
 * @package Kuoqi\Worker
 */
class Event{

    protected $event = array(
        'connect'=>'',//链接的时候执行
        'message'=>'',//发送消息的时候执行
        'close'=>'',//关闭时候执行
    );

    public function bind($event,$function){
        $this->event[$event] = $function;
    }

    public function error($msg){
        throw new \Kuoqi\Error("event error");
    }

    public function log($msg){
        //echo $msg;
        //throw new \Kuoqi\Error("event log");
        echo $msg.PHP_EOL;
    }

    public function say($msg){
        //todo--say
        //throw new \Kuoqi\Error("event say");
    }


    //开始执行
    public function start(){
        $this->run();
    }

    //执行运行
    public function run(){
        while(true){
            $this->listen();
        }
    }

}